<!-- S search -->
<app-search-bar
  [submitLoading]="tableParams.loading"
  [searchOptions]="searchOptions"
  labelFlex="90px"
  (onSearch)="queryData($event)"
  (onReset)="resetData($event)"
>
</app-search-bar>
<!-- E search -->

<nz-card class="m-t-2">
  <div class="pagination-wrap-position table-wrap">
    <nz-table
      #basicTable
      nzSize="small"
      nzShowSizeChanger
      nzShowQuickJumper
      nzOuterBordered
      [nzScroll]="{ x: '1100px' }"
      [nzFrontPagination]="false"
      [nzLoadingDelay]="100"
      [nzLoading]="tableParams.loading"
      [nzData]="tableParams.tableData"
      [nzPageSizeOptions]="[5, 10, 20, 50, 100]"
      [nzTotal]="tableParams.total"
      [nzPageIndex]="tableParams.page"
      [nzPageSize]="tableParams.pageSize"
      [nzShowTotal]="totalTemplate"
      (nzPageIndexChange)="onPageIndexChange($event)"
      (nzPageSizeChange)="onPageSizeChange($event)"
    >
      <thead>
        <tr>
          <th nzAlign="center" nzWidth="180px" nzLeft>订单编号</th>
          <th nzAlign="center" nzWidth="180px">订单状态</th>
          <th nzAlign="center" nzWidth="200px">直降活动</th>
          <th nzAlign="center" nzWidth="120px">用户ID</th>
          <th nzAlign="center" nzWidth="120px">应付金额</th>
          <th nzAlign="center" nzWidth="120px">实付金额</th>
          <th nzAlign="center" nzWidth="120px">优惠总额</th>
          <th nzAlign="center" nzWidth="120px">本优惠抵值</th>
          <th nzAlign="center" nzWidth="170px">下单时间</th>
          <th nzAlign="center" nzWidth="170px">付款时间</th>
          <th nzAlign="center" nzWidth="200px" nzRight>操作</th>
        </tr>
      </thead>

      <tbody>
        <tr *ngFor="let data of basicTable.data; let index = index;">
          <!-- 订单编号 -->
          <td nzAlign="center" nzLeft>{{ data.orderNum || '-' }}</td>

          <!-- 订单状态 -->
          <td nzAlign="center">
            <span
              *ngIf="data.status"
              [ngStyle]="{'color': data.status | sencondDescentStatus: 'color'}">
              {{ data.status | sencondDescentStatus: 'label' }}
            </span>
          </td>

          <!-- 直降活动 -->
          <td nzAlign="center">
            <a
              nz-button
              nzType="link"
              [disabled]="!data.activityName"
              target="_blank"
              routerLink="/used-store/second-descent-details"
              [queryParams]="{type: 2, id: data.activityId}"
            >{{ data.activityName }} [{{ data.activityId }}]</a>
          </td>

          <!-- 用户ID -->
          <td nzAlign="center">
            <a
              nz-button
              nzType="link"
              [disabled]="!data.userId"
              target="_blank"
              [routerLink]="['/customer/tabs', data.userId, 0]"
            >{{ data.userId }}</a>
          </td>

          <!-- 应付金额 -->
          <td nzAlign="center">{{ data.totalPrice || '0' }}</td>

          <!-- 实付金额 -->
          <td nzAlign="center">{{ data.realPrice || '0' }}</td>

          <!-- 优惠总额 -->
          <td nzAlign="center">{{ data.favorablePrice || '-' }}</td>

          <!-- 本优惠抵值 -->
          <td nzAlign="center">{{ data.discountValue || '0' }}</td>

          <!-- 下单时间 -->
          <td nzAlign="center">{{ data.orderTime || '-' }}</td>

          <!-- 付款时间 -->
          <td nzAlign="center">{{ data.payTime || '-' }}</td>

          <!-- 操作 -->
          <td nzAlign="center" nzRight>
            <button
              nz-button
              nzSize="small"
              nzType="link"
              (click)="showFollowModal(data)"
            >跟进订单</button>
            <button
              *ngIf="[5, 6, 7].includes(data.status) && permission.userPermission.has('secondDesrecord:cancelOrder')"
              nz-button
              nzSize="small"
              nzType="link"
              nzDanger
              (click)="cannlOrder(data)"
            >取消订单</button>
          </td>
        </tr>
      </tbody>
    </nz-table>

    <!-- 分页template -->
    <ng-template #totalTemplate let-total>共有 {{ total }} 条</ng-template>
  </div>
</nz-card>

<!-- 跟进Component -->
<app-follow-up #followUpRef [initParams]="initParams" [ohterParams]="{ type: 1 }"></app-follow-up>